<!--
// (c) Norbert Huffschmid
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
-->

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sd="clr-namespace:SpinDotters.Core;assembly=SpinDotters.Core"
    xmlns:sdw="clr-namespace:SpinDotters.Widgets"
    xmlns:cnv="clr-namespace:SpinDotters.Widgets.Converter"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
    <!-- vsm: assembly is patched to PresentationFramework in case of WPF build -->

    <SolidColorBrush x:Key="WidgetsDefaultBrush">DodgerBlue</SolidColorBrush>

    <cnv:FontSizeConverter x:Key="fontSizeConverter" />
    <cnv:BoolToVisibilityConverter x:Key="boolToVisibilityConverter" />
    
    <Style x:Key="sdw:SpinDottersButton" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid RenderTransformOrigin="0.5,0.5">
                        <Grid.RenderTransform>
                            <ScaleTransform x:Name="scaleTransform" />
                        </Grid.RenderTransform>

                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal" />
                                <vsm:VisualState x:Name="MouseOver" />
                                <vsm:VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ColorAnimation Duration="0" 
                                                        Storyboard.TargetName="BackgroundGradient" 
                                                        Storyboard.TargetProperty="(Ellipse.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
                                                        To="White"/>
                                        <DoubleAnimation Duration="0"
                                                         Storyboard.TargetName="scaleTransform"
                                                         Storyboard.TargetProperty="ScaleX"
                                                         To="0.95"/>
                                        <DoubleAnimation Duration="0"
                                                         Storyboard.TargetName="scaleTransform"
                                                         Storyboard.TargetProperty="ScaleY"
                                                         To="0.95"/>
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Disabled" />
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>

                        <Ellipse Fill="{TemplateBinding Background}"  />
                        <Ellipse x:Name="BackgroundGradient">
                            <Ellipse.Fill>
                                <RadialGradientBrush GradientOrigin="0.2, 0.2">
                                    <GradientStop Offset="0.1" Color="LightGray" />
                                    <GradientStop Offset="1" Color="Transparent" />
                                </RadialGradientBrush>
                            </Ellipse.Fill>
                        </Ellipse>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="sdw:ClockBase">
        <Setter Property="SpinningControlsBorderBrush" Value="DarkGray" />
        <Setter Property="SpinningControlsBorderThickness" Value="3" />
        <Setter Property="Reflective" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sdw:ClockBase">
                    <Grid Background="Transparent"
                          HorizontalAlignment="Center">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="PulseStates">
                                <vsm:VisualState x:Name="Pulsing">
                                    <Storyboard AutoReverse="True" RepeatBehavior="Forever">
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="hoursMinutesSeparator" 
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="0.6" />
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="0" />
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:1.0" Value="0.6" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="minutesSecondsSeparator" 
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.0" Value="0.6" />
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.5" Value="0" />
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:1.0" Value="0.6" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="NonPulsing" />
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>

                        <sd:NumericUpDown Grid.Column="0"
                                                  Value="{Binding Path=HoursHigh}"
                                                  Maximum="{Binding Path=HoursHighMaximum}"
                                                  ShowZeroAsBlank="{Binding Path=HoursHighShowZeroAsBlank}"
                                                  VerticalAlignment="Stretch"
                                                  ReadOnly="True"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}" />
                        <sd:DomainUpDown Grid.Column="0"
                                                 VerticalAlignment="Bottom"
                                                 ReadOnly="True"
                                                 HorizontalContentAlignment="Left"
                                                 FontSize="{Binding Path=FontSize, Converter={StaticResource fontSizeConverter}, ConverterParameter=0.25}"
                                                 Background="Transparent"
                                                 BorderThickness="0"
                                                 Margin="{TemplateBinding SpinningControlsBorderThickness}"
                                                 SelectedIndex="{Binding AmPmIndex}"
                                                 Visibility="{Binding AntePostMeridiemVisibility}">
                            <TextBlock Text="AM" />
                            <TextBlock Text="PM" />
                        </sd:DomainUpDown>
                        <sd:NumericUpDown Grid.Column="1"
                                                  Value="{Binding Path=HoursLow}"
                                                  VerticalAlignment="Stretch"
                                                  ReadOnly="True"
                                                  Margin="2,0,0,0"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}" />
                        <TextBlock x:Name="hoursMinutesSeparator" 
                                   Grid.Column="2"
                                   Text="&#183;"
                                   Opacity="0.6" />
                        <sd:NumericUpDown Grid.Column="3"
                                                  Value="{Binding Path=MinutesHigh}"
                                                  VerticalAlignment="Stretch"
                                                  Maximum="5"
                                                  ReadOnly="True"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}" />
                        <sd:NumericUpDown Grid.Column="4"
                                                  Value="{Binding Path=MinutesLow}"
                                                  VerticalAlignment="Stretch"
                                                  ReadOnly="True"
                                                  Margin="2,0,0,0"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}" />
                        <TextBlock x:Name="minutesSecondsSeparator"
                                   Grid.Column="5"
                                   Text="&#183;"
                                   Opacity="0.6"
                                   Visibility="{Binding Path=HasSeconds,
                                                        Converter={StaticResource boolToVisibilityConverter}}" />
                        <sd:NumericUpDown Grid.Column="6"
                                                  Value="{Binding Path=SecondsHigh}"
                                                  VerticalAlignment="Stretch"
                                                  Maximum="5"
                                                  ReadOnly="True"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                                  Visibility="{Binding Path=HasSeconds,
                                                                       Converter={StaticResource boolToVisibilityConverter}}" />
                        <sd:NumericUpDown Grid.Column="7"
                                                  Value="{Binding Path=SecondsLow}"
                                                  VerticalAlignment="Stretch"
                                                  ReadOnly="True"
                                                  Margin="2,0,0,0"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                                  Visibility="{Binding Path=HasSeconds,
                                                                       Converter={StaticResource boolToVisibilityConverter}}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="sdw:Clock">
        <Setter Property="SpinningControlsBorderBrush" Value="DarkGray" />
        <Setter Property="SpinningControlsBorderThickness" Value="3" />
        <Setter Property="Reflective" Value="True" />
        <Setter Property="BorderBrush" Value="DarkGray" />
        <Setter Property="BorderThickness" Value="3" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="FontSize" Value="36" />
        <Setter Property="TimeFormat" Value="Automatic" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sdw:Clock">
                    <Border BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Padding="{TemplateBinding Padding}"
                            CornerRadius="5"
                            Background="{TemplateBinding Background}">
                        <sdw:ClockBase Pulse="True"
                                       SpinningControlsBackground="{TemplateBinding SpinningControlsBackground}"
                                       SpinningControlsBorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                       SpinningControlsBorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                       Reflective="{TemplateBinding Reflective}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="sdw:StopWatch">
        <Setter Property="SpinningControlsBorderBrush" Value="DarkGray" />
        <Setter Property="SpinningControlsBorderThickness" Value="3" />
        <Setter Property="Reflective" Value="True" />
        <Setter Property="BorderBrush" Value="DarkGray" />
        <Setter Property="BorderThickness" Value="3" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="FontSize" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sdw:StopWatch">
                    <Border BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Padding="{TemplateBinding Padding}"
                            CornerRadius="5"
                            Background="{TemplateBinding Background}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Button x:Name="PART_ResetButton" 
                                    VerticalAlignment="Stretch"
                                    Style="{StaticResource sdw:SpinDottersButton}"
                                    Margin="6, 0"
                                    Background="Red"
                                    Grid.Column="0" />
                            <sdw:ClockBase Grid.Column="1"
                                           Pulse="{Binding Path=IsRunning}"
                                           SpinningControlsBackground="{TemplateBinding SpinningControlsBackground}"
                                           SpinningControlsBorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                           SpinningControlsBorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                           Reflective="{TemplateBinding Reflective}"/>
                            <Button x:Name="PART_StartStopButton"
                                    VerticalAlignment="Stretch"
                                    Style="{StaticResource sdw:SpinDottersButton}"
                                    Margin="6, 0"
                                    Background="Green"
                                    Grid.Column="2"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="sdw:Counter">
        <Setter Property="BorderBrush" Value="DarkGray" />
        <Setter Property="BorderThickness" Value="3" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="FontSize" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sdw:Counter">
                    <Border BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Padding="{TemplateBinding Padding}"
                            CornerRadius="5"
                            Background="{TemplateBinding Background}">
                        <StackPanel Orientation="Horizontal"
                                    HorizontalAlignment="Center">
                            <sd:NumericUpDown Value="{Binding Path=Value5, Mode=TwoWay}"
                                                      Visibility="{Binding Path=Visibility5}"
                                                      Reflective="{Binding Path=Reflective}"
                                                      ReadOnly="{Binding Path=ReadOnly}"
                                                      Background="{Binding Path=SpinningControlsBackground}"/>
                            <sd:NumericUpDown Value="{Binding Path=Value4, Mode=TwoWay}"
                                                      Visibility="{Binding Path=Visibility4}"
                                                      Reflective="{Binding Path=Reflective}"
                                                      ReadOnly="{Binding Path=ReadOnly}"
                                                      Background="{Binding Path=SpinningControlsBackground}"/>
                            <sd:NumericUpDown Value="{Binding Path=Value3, Mode=TwoWay}"
                                                      Visibility="{Binding Path=Visibility3}"
                                                      Reflective="{Binding Path=Reflective}"
                                                      ReadOnly="{Binding Path=ReadOnly}"
                                                      Background="{Binding Path=SpinningControlsBackground}"/>
                            <sd:NumericUpDown Value="{Binding Path=Value2, Mode=TwoWay}"
                                                      Visibility="{Binding Path=Visibility2}"
                                                      Reflective="{Binding Path=Reflective}"
                                                      ReadOnly="{Binding Path=ReadOnly}"
                                                      Background="{Binding Path=SpinningControlsBackground}"/>
                            <sd:NumericUpDown Value="{Binding Path=Value1, Mode=TwoWay}"
                                                      Visibility="{Binding Path=Visibility1}"
                                                      Reflective="{Binding Path=Reflective}"
                                                      ReadOnly="{Binding Path=ReadOnly}"
                                                      Background="{Binding Path=SpinningControlsBackground}"/>
                            <sd:NumericUpDown Value="{Binding Path=Value0, Mode=TwoWay}"
                                                      Visibility="{Binding Path=Visibility0}"
                                                      Reflective="{Binding Path=Reflective}"
                                                      ReadOnly="{Binding Path=ReadOnly}"
                                                      Background="{Binding Path=SpinningControlsBackground}"/>
                            <Button x:Name="PART_ResetButton" 
                                    VerticalAlignment="Stretch"
                                    Style="{StaticResource sdw:SpinDottersButton}"
                                    Margin="{TemplateBinding Padding}"
                                    Background="{StaticResource WidgetsDefaultBrush}"
                                    Visibility="{Binding Path=ResetButtonVisibility}"/>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="sdw:DatePicker">
        <Setter Property="SpinningControlsBorderBrush" Value="DarkGray" />
        <Setter Property="SpinningControlsBorderThickness" Value="3" />
        <Setter Property="Reflective" Value="True" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="FontSize" Value="20" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sdw:DatePicker">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="3*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="3*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="ValidityStates">
                                <vsm:VisualState x:Name="Valid" />
                                <vsm:VisualState x:Name="Invalid">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                                       Storyboard.TargetName="dayHigh"
                                                                       AutoReverse="True" 
                                                                       RepeatBehavior="Forever">
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.100" Value="0.2" />
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.200" Value="1.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                                       Storyboard.TargetName="dayLow"
                                                                       AutoReverse="True" 
                                                                       RepeatBehavior="Forever">
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.100" Value="0.2" />
                                            <DiscreteDoubleKeyFrame KeyTime="0:0:0.200" Value="1.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>

                        <sd:DomainUpDown Grid.Column="0"
                                                 VerticalAlignment="Center"
                                                 ReadOnly="True"
                                                 Margin="{TemplateBinding Padding}"
                                                 Background="{TemplateBinding SpinningControlsBackground}"
                                                 Reflective="{TemplateBinding Reflective}"
                                                 BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                 BorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                                 ItemsSource="{Binding Path=DayNames}"
                                                 SelectedIndex="{Binding Path=DayNameIndex}" />
                        <sd:NumericUpDown Grid.Column="1"
                                                  x:Name="dayHigh"
                                                  FontSize="{Binding Path=FontSize, Converter={StaticResource fontSizeConverter}, ConverterParameter=4.0}"
                                                  Margin="{TemplateBinding Padding}"
                                                  Maximum="3"
                                                  ShowZeroAsBlank="True"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                                  Value="{Binding Path=DayHigh, Mode=TwoWay}" />
                        <sd:NumericUpDown Grid.Column="2"
                                                  x:Name="dayLow"
                                                  FontSize="{Binding Path=FontSize, Converter={StaticResource fontSizeConverter}, ConverterParameter=4.0}"
                                                  Margin="{TemplateBinding Padding}"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                                  Value="{Binding Path=DayLow, Mode=TwoWay}" />
                        <sd:DomainUpDown Grid.Column="3"
                                                 VerticalAlignment="Center"
                                                 Margin="{TemplateBinding Padding}"
                                                 Background="{TemplateBinding SpinningControlsBackground}"
                                                 Reflective="{TemplateBinding Reflective}"
                                                 BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                 BorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                                 ItemsSource="{Binding Path=MonthNames}"
                                                 SelectedIndex="{Binding Path=MonthNameIndex, Mode=TwoWay}" />
                        <sd:NumericUpDown Grid.Column="4"
                                                  VerticalAlignment="Center"
                                                  Margin="{TemplateBinding Padding}"
                                                  Background="{TemplateBinding SpinningControlsBackground}"
                                                  Reflective="{TemplateBinding Reflective}"
                                                  BorderBrush="{TemplateBinding SpinningControlsBorderBrush}"
                                                  BorderThickness="{TemplateBinding SpinningControlsBorderThickness}"
                                                  Minimum="{Binding Path=YearMinimum}"
                                                  Value="{Binding Path=Year, Mode=TwoWay}"
                                                  Maximum="{Binding Path=YearMaximum}"
                                                  Visibility="{Binding Path=YearVisibility}" />
                        <sd:JogDial x:Name="PART_JogDial"
                                    Grid.Column="5"
                                    Width="50"
                                    Visibility="{Binding Path=JogDialVisibility}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
